package tabs;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.border.TitledBorder;

import main.EditorInterface;

/**
 * Classe da aba de configuração gerais do objeto.
 * 
 * @author Renato Nunes
 */
@SuppressWarnings("serial")
public class MainTab extends JPanel 
{

	/**
    * Classe pai da aba.
    */
    private EditorInterface parent;
   
	/**
	* Campos das configurações gerais do objeto.
	*/
	private JTextField objectNameField;
	//private JTextField headerWidthField;
	//private JTextField headerHeightField;
	private JTextField headerPathField;
	//private JTextField footerWidthField;
	//private JTextField footerHeightField;
	private JTextField footerPathField;

	public MainTab( EditorInterface parent )
	{
		this.parent = parent;
		
		setLayout( null );
		
		setupFields();
		setupButtons();
	}
	
	/**
	 *	Executa a configuração do formulário da aba de configurações gerais do objeto. 
	 */
	public void setupFields()
	{
		JLabel lblNewLabel_1 = new JLabel("Nome do objeto: ");
		lblNewLabel_1.setBounds(10, 20, 150, 20);
		add(lblNewLabel_1);
		
		objectNameField = new JTextField();
		objectNameField.setBounds(160, 20, 470, 20);
		objectNameField.setColumns(10);
		add(objectNameField);
		
		JPanel panel_2 = new JPanel();
		panel_2.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Cabeçalho", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel_2.setBounds(10, 60, 680, 120);
		panel_2.setLayout(null);
		add(panel_2);
		
		JLabel lblCaminhoDaImagem = new JLabel( "Nome da imagem (com extensão): " );
		lblCaminhoDaImagem.setBounds( 10, 30, 200, 20 );
		panel_2.add(lblCaminhoDaImagem);
		
		/*JLabel lblWidth = new JLabel("Largura: ");
		lblWidth.setBounds(10, 60, 130, 20);
		panel_2.add(lblWidth);
		
		JLabel lblAltura = new JLabel("Altura: ");
		lblAltura.setBounds(10, 90, 130, 20);
		panel_2.add(lblAltura);*/
		
		headerPathField = new JTextField();
		headerPathField.setColumns(10);
		headerPathField.setBounds( 220, 30, 400, 20 );
		panel_2.add( headerPathField );
		
		/*headerWidthField = new JTextField();
		headerWidthField.setBounds(150, 60, 470, 20);
		headerWidthField.setColumns(10);
		panel_2.add(headerWidthField);

		headerHeightField = new JTextField();
		headerHeightField.setColumns(10);
		headerHeightField.setBounds(150, 90, 470, 20);
		panel_2.add(headerHeightField); */
		
		JPanel panel_3 = new JPanel();
		panel_3.setLayout(null);
		panel_3.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Rodapé", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel_3.setBounds(10, 200, 680, 120);
		add(panel_3);
		
		JLabel label_2 = new JLabel( "Nome da imagem (com extensão): " );
		label_2.setBounds( 10, 30, 200, 20 );
		panel_3.add(label_2);
		
		/*JLabel label = new JLabel("Largura: ");
		label.setBounds(10, 60, 130, 20);
		panel_3.add(label);
		
		JLabel label_1 = new JLabel("Altura: ");
		label_1.setBounds(10, 90, 130, 20);
		panel_3.add(label_1);*/
		
		footerPathField = new JTextField();
		footerPathField.setColumns( 10 );
		footerPathField.setBounds( 220, 30, 400, 20 );
		panel_3.add( footerPathField );
		
		/*footerWidthField = new JTextField();
		footerWidthField.setColumns(10);
		footerWidthField.setBounds(150, 60, 470, 20);
		panel_3.add(footerWidthField);
		
		footerHeightField = new JTextField();
		footerHeightField.setColumns(10);
		footerHeightField.setBounds(150, 90, 470, 20);
		panel_3.add(footerHeightField);*/
	}
	
	/**
	 *	Executa a configuração dos botões da aba de configurações gerais do objeto. 
	 */
	public void setupButtons()
	{
		JButton okBtn = new JButton( "OK" );
		okBtn.setBounds( 330, 340, 60, 20 );
		okBtn.addActionListener( new ActionListener() {

			public void actionPerformed(ActionEvent arg0) 
			{
				okClicked();
			}
		});
		add( okBtn );
	}
	
	/**
	* Carrega os elementos da página com os atributos do objeto aberto.
	*/
   public void loadTab()
   {
	   //TODO: VERIFICAR SE EXISTE UM OBJETO ABERTO.
	   objectNameField.setText( parent.getObjectName() );
		
	   //headerHeightField.setText( parent.getHeader().getHeight() );
	   //headerWidthField.setText( parent.getHeader().getWidth() );
	   headerPathField.setText( parent.getHeader().getPath() );
		
	   //footerHeightField.setText( parent.getFooter().getHeight() );
	   //footerWidthField.setText( parent.getFooter().getWidth() );
	   footerPathField.setText( parent.getFooter().getPath() );
   }
   
   /**
	 * Limpa as propriedades gerais do objeto.
	 */
	public void clearProp()
	{
		objectNameField.setText( "" );

		//headerHeightField.setText( "" );
		//headerWidthField.setText( "" );
		headerPathField.setText( "" );
		
		//footerHeightField.setText( "" );
		//footerWidthField.setText( "" );
		footerPathField.setText( "" );
	}
	
	/**
	 *	Atualiza as informações do objeto na classe que salva o mesmo. 
	 */
	private void okClicked()
	{
		parent.setObjectName( objectNameField.getText() );
		parent.getHeader().setPath( headerPathField.getText() );
		parent.getFooter().setPath( footerPathField.getText() );
	}
}
